package leetcode.median;

import java.util.HashSet;

/**
 * ClassName: $128_LongestConsecutive
 * Description:
 * date: 2022-02-19 18:43
 *
 * @author liyifan
 */
public class $128_LongestConsecutive {
    public int longestConsecutive(int[] nums) {
        HashSet<Integer> set = new HashSet<>(nums.length);
        for (Integer x:nums) {set.add(x);}

        int res = 0;
        for (int i = 0;i < nums.length;i++) {
            if (set.contains(nums[i] - 1)){continue;}
            int cur = nums[i];
            int cnt = 1;
            while (set.contains(cur + 1)) {
                cur++;
                cnt++;
            }
            res = Math.max(res, cnt);
        }
        return res;
    }
}
